<template>
  <el-dialog :visible="showRoleDialog" title="分配权限李路平">
    <!-- 一个复选框 -->
    <!-- <el-checkbox-grop></el-checkbox-grop> -->
    <el-checkbox-group v-model="roleIds">
      <!-- 选项 -->
      <el-checkbox v-for="item in list" :key="item.id" :label="item.id">
        {{ item.name }}
      </el-checkbox>
    </el-checkbox-group>
    <!-- 发送请求的按钮 -->
    <el-row slot="footer" type="flex" justify="center">
      <el-col :span="6">
        <el-button type="primary" @click="btnOk">确定</el-button>
        <el-button @click="btnCancle">取消</el-button>
      </el-col>
    </el-row>
  </el-dialog>
</template>

<script>
// 引入获取角色的接口
import { getTableList } from '@/api/setting'
// 回显角色权限
import { getUserDetailById } from '@/api/user'
// 引入权限提交按钮
import { assignRoles } from '@/api/employees'
export default {
  props: {
    showRoleDialog: {
      type: Boolean,
      default: false
    },
    userId: {
      type: String,
      default: null,
      require: true
    }
  },
  data() {
    return {
      list: [],
      roleIds: []
    }
  },
  methods: {
    async btnOk() {
      await assignRoles({ id: this.userId, roleIds: this.roleIds })
      // 关闭弹窗
      this.$emit('update:showRoleDialog', false)
      this.$message.success('恭喜你 权限提交成功')
    },
    btnCancle() {
      this.roleIds = []
      this.$emit('update:showRoleDialog', false)
      this.$message.warning('取消成功')
    },
    async getTableList() {
      const { rows } = await getTableList()
      this.list = rows
    },
    async getUserDetailById(id) {
      const { roleIds } = await getUserDetailById(id)
      this.roleIds = roleIds // 赋值本用户的角色
    }
    // getUserDetailById(id) {
    //   const { roleIds } = getUserDetailById(id)
    //   this.roleIds = roleIds
    // }
  },
  created() {
    this.getTableList()
    // this.getUserDetailById()
  }
}
</script>

<style></style>
